﻿using NBehave.Spec.NUnit;
using NUnit.Framework;

namespace SilverlightCalculator.Tests
{
    [TestFixture]
    public class When_using_the_ValidatiorBase
    {
        private ValidationBase _validationBase;

        [SetUp]
        public void SetUp()
        {
            _validationBase = new ValidationBase();
        }

        [Test]
        public void HasErrors_should_return_true_when_errors_exist()
        {
            // Arrange
            _validationBase.AddError("X", "X");

            // Act
            var result = _validationBase.HasErrors();

            // Assert
            result.ShouldBeTrue();
        }

        [Test]
        public void HasErrors_should_return_false_when_no_errors_exist()
        {
            // Arrange
            // collection will be empty at this point

            // Act
            var result = _validationBase.HasErrors();

            // Assert
            result.ShouldBeFalse();
        }
       
        [Test]
        public void Should_be_able_to_return_message_for_error()
        {
            
            // Arrange
            const string errorMessage = "ErrorMessageText";
            _validationBase.AddError("X", errorMessage);

            // Act
            var result = _validationBase.GetErrorMessageForProperty("X");

            // Assert
            result.ShouldEqual(errorMessage);
        }

        [Test]
        public void Should_return_null_if_message_does_not_exist_for_error()
        {
            // Arrange
            // collection will be empty at this point

            // Act
            var result = _validationBase.GetErrorMessageForProperty("X");

            // Assert
            result.ShouldBeNull();
        }
    }
}